package com.koushikdutta.ion.bitmap;

import com.koushikdutta.async.util.LruCache;

class LruBitmapCache extends LruCache<String, BitmapInfo> {
    private SoftReferenceHashtable<String, BitmapInfo> soft = new SoftReferenceHashtable();

    public LruBitmapCache(int maxSize) {
        super((long) maxSize);
    }

    protected long sizeOf(String key, BitmapInfo info) {
        return (long) info.sizeOf();
    }

    public BitmapInfo getBitmapInfo(String key) {
        BitmapInfo ret = (BitmapInfo) get(key);
        if (ret != null) {
            return ret;
        }
        ret = (BitmapInfo) this.soft.remove(key);
        if (ret != null) {
            put(key, ret);
        }
        return ret;
    }

    protected void entryRemoved(boolean evicted, String key, BitmapInfo oldValue, BitmapInfo newValue) {
        super.entryRemoved(evicted, key, oldValue, newValue);
        if (evicted) {
            this.soft.put(key, oldValue);
        }
    }
}
